

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="python" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="python" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>QUANTAXIS.QAIndicator.indicators &mdash; QUANTAXIS 1.0.39 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> QUANTAXIS
          

          
          </a>

          
            
            
              <div class="version">
                1.0.39
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">QUANTAXIS</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>QUANTAXIS.QAIndicator.indicators</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for QUANTAXIS.QAIndicator.indicators</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding:utf-8</span>
<span class="c1">#</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016-2018 yutiansut/QUANTAXIS</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in all</span>
<span class="c1"># copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<span class="c1"># SOFTWARE.</span>

<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">reduce</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>

<span class="kn">from</span> <span class="nn">QUANTAXIS.QAIndicator.base</span> <span class="k">import</span> <span class="o">*</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">DataFrame 类</span>

<span class="sd">以下的函数都可以被直接add_func</span>


<span class="sd">&quot;&quot;&quot;</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">1.	趋向指标 </span>
<span class="sd">又叫趋势跟踪类指标,主要用于跟踪并预测股价的发展趋势</span>

<span class="sd">包含的主要指标</span>
<span class="sd">1. 移动平均线 MA</span>
<span class="sd">2. 指数平滑移动平均线 MACD</span>
<span class="sd">3. 趋向指标 DMI</span>
<span class="sd">4. 瀑布线 PBX</span>
<span class="sd">5. 平均线差 DMA</span>
<span class="sd">6. 动力指标(动量线)  MTM</span>
<span class="sd">7. 指数平均线 EXPMA</span>
<span class="sd">8. 佳庆指标 CHO</span>
<span class="sd">&quot;&quot;&quot;</span>


<div class="viewcode-block" id="QA_indicator_MA"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_MA">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_MA</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="p">):</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;MA&#39;</span><span class="p">:</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N</span><span class="p">)})</span></div>


<div class="viewcode-block" id="QA_indicator_EMA"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_EMA">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_EMA</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="p">):</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;EMA&#39;</span><span class="p">:</span> <span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N</span><span class="p">)})</span></div>


<div class="viewcode-block" id="QA_indicator_SMA"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_SMA">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_SMA</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="p">):</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;SMA&#39;</span><span class="p">:</span> <span class="n">SMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N</span><span class="p">)})</span></div>


<div class="viewcode-block" id="QA_indicator_MACD"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_MACD">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_MACD</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">short</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">long</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">mid</span><span class="o">=</span><span class="mi">9</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    MACD CALC</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>

    <span class="n">DIF</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">short</span><span class="p">)</span><span class="o">-</span><span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">long</span><span class="p">)</span>
    <span class="n">DEA</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">DIF</span><span class="p">,</span> <span class="n">mid</span><span class="p">)</span>
    <span class="n">MACD</span> <span class="o">=</span> <span class="p">(</span><span class="n">DIF</span><span class="o">-</span><span class="n">DEA</span><span class="p">)</span><span class="o">*</span><span class="mi">2</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;DIF&#39;</span><span class="p">:</span> <span class="n">DIF</span><span class="p">,</span> <span class="s1">&#39;DEA&#39;</span><span class="p">:</span> <span class="n">DEA</span><span class="p">,</span> <span class="s1">&#39;MACD&#39;</span><span class="p">:</span> <span class="n">MACD</span><span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_DMI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_DMI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_DMI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    趋向指标 DMI</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">OPEN</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span>

    <span class="n">TR</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="n">HIGH</span><span class="o">-</span><span class="n">LOW</span><span class="p">,</span> <span class="n">ABS</span><span class="p">(</span><span class="n">HIGH</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">))),</span>
                 <span class="n">ABS</span><span class="p">(</span><span class="n">LOW</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">))),</span> <span class="n">M1</span><span class="p">)</span>
    <span class="n">HD</span> <span class="o">=</span> <span class="n">HIGH</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">HIGH</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">LD</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">LOW</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">-</span><span class="n">LOW</span>
    <span class="n">DMP</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">HD</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">HD</span> <span class="o">&gt;</span> <span class="n">LD</span><span class="p">,</span> <span class="n">HD</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">M1</span><span class="p">)</span>
    <span class="n">DMM</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">LD</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">LD</span> <span class="o">&gt;</span> <span class="n">HD</span><span class="p">,</span> <span class="n">LD</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">M1</span><span class="p">)</span>
    <span class="n">DI1</span> <span class="o">=</span> <span class="n">DMP</span><span class="o">*</span><span class="mi">100</span><span class="o">/</span><span class="n">TR</span>
    <span class="n">DI2</span> <span class="o">=</span> <span class="n">DMM</span><span class="o">*</span><span class="mi">100</span><span class="o">/</span><span class="n">TR</span>
    <span class="n">ADX</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">DI2</span><span class="o">-</span><span class="n">DI1</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">DI1</span><span class="o">+</span><span class="n">DI2</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span><span class="p">,</span> <span class="n">M2</span><span class="p">)</span>
    <span class="n">ADXR</span> <span class="o">=</span> <span class="p">(</span><span class="n">ADX</span><span class="o">+</span><span class="n">REF</span><span class="p">(</span><span class="n">ADX</span><span class="p">,</span> <span class="n">M2</span><span class="p">))</span><span class="o">/</span><span class="mi">2</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;DI1&#39;</span><span class="p">:</span> <span class="n">DI1</span><span class="p">,</span> <span class="s1">&#39;DI2&#39;</span><span class="p">:</span> <span class="n">DI2</span><span class="p">,</span>
        <span class="s1">&#39;ADX&#39;</span><span class="p">:</span> <span class="n">ADX</span><span class="p">,</span> <span class="s1">&#39;ADXR&#39;</span><span class="p">:</span> <span class="n">ADXR</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_PBX"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_PBX">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_PBX</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N1</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">N2</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">N3</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">N4</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="n">N5</span><span class="o">=</span><span class="mi">18</span><span class="p">,</span> <span class="n">N6</span><span class="o">=</span><span class="mi">24</span><span class="p">):</span>
    <span class="s1">&#39;瀑布线&#39;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">PBX1</span> <span class="o">=</span> <span class="p">(</span><span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N1</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">N1</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">N1</span><span class="p">))</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">PBX2</span> <span class="o">=</span> <span class="p">(</span><span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N2</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">N2</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">N2</span><span class="p">))</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">PBX3</span> <span class="o">=</span> <span class="p">(</span><span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N3</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">N3</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">N3</span><span class="p">))</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">PBX4</span> <span class="o">=</span> <span class="p">(</span><span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N4</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">N4</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">N4</span><span class="p">))</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">PBX5</span> <span class="o">=</span> <span class="p">(</span><span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N5</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">N5</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">N5</span><span class="p">))</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">PBX6</span> <span class="o">=</span> <span class="p">(</span><span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N6</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">N6</span><span class="p">)</span> <span class="o">+</span> <span class="n">EMA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">4</span> <span class="o">*</span> <span class="n">N6</span><span class="p">))</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;PBX1&#39;</span><span class="p">:</span> <span class="n">PBX1</span><span class="p">,</span> <span class="s1">&#39;PBX2&#39;</span><span class="p">:</span> <span class="n">PBX2</span><span class="p">,</span> <span class="s1">&#39;PBX3&#39;</span><span class="p">:</span> <span class="n">PBX3</span><span class="p">,</span>
            <span class="s1">&#39;PBX4&#39;</span><span class="p">:</span> <span class="n">PBX4</span><span class="p">,</span> <span class="s1">&#39;PBX5&#39;</span><span class="p">:</span> <span class="n">PBX5</span><span class="p">,</span> <span class="s1">&#39;PBX6&#39;</span><span class="p">:</span> <span class="n">PBX6</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_DMA"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_DMA">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_DMA</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">M3</span><span class="o">=</span><span class="mi">10</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    平均线差 DMA</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">DDD</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span> <span class="o">-</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">M2</span><span class="p">)</span>
    <span class="n">AMA</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">DDD</span><span class="p">,</span> <span class="n">M3</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;DDD&#39;</span><span class="p">:</span> <span class="n">DDD</span><span class="p">,</span> <span class="s1">&#39;AMA&#39;</span><span class="p">:</span> <span class="n">AMA</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_MTM"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_MTM">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_MTM</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
    <span class="s1">&#39;动量线&#39;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">mtm</span> <span class="o">=</span> <span class="n">C</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">MTMMA</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">mtm</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;MTM&#39;</span><span class="p">:</span> <span class="n">mtm</span><span class="p">,</span> <span class="s1">&#39;MTMMA&#39;</span><span class="p">:</span> <span class="n">MTMMA</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_EXPMA"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_EXPMA">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_EXPMA</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">P1</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">P2</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">P3</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">P4</span><span class="o">=</span><span class="mi">60</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; 指数平均线 EXPMA&quot;&quot;&quot;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">MA1</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">P1</span><span class="p">)</span>
    <span class="n">MA2</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">P2</span><span class="p">)</span>
    <span class="n">MA3</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">P3</span><span class="p">)</span>
    <span class="n">MA4</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">P4</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;MA1&#39;</span><span class="p">:</span> <span class="n">MA1</span><span class="p">,</span> <span class="s1">&#39;MA2&#39;</span><span class="p">:</span> <span class="n">MA2</span><span class="p">,</span> <span class="s1">&#39;MA3&#39;</span><span class="p">:</span> <span class="n">MA3</span><span class="p">,</span> <span class="s1">&#39;MA4&#39;</span><span class="p">:</span> <span class="n">MA4</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_CHO"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_CHO">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_CHO</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N1</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">N2</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    佳庆指标 CHO</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">MID</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">VOL</span><span class="o">*</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">CLOSE</span><span class="o">-</span><span class="n">HIGH</span><span class="o">-</span><span class="n">LOW</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">HIGH</span><span class="o">+</span><span class="n">LOW</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">CHO</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">MID</span><span class="p">,</span> <span class="n">N1</span><span class="p">)</span><span class="o">-</span><span class="n">MA</span><span class="p">(</span><span class="n">MID</span><span class="p">,</span> <span class="n">N2</span><span class="p">)</span>
    <span class="n">MACHO</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">CHO</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;CHO&#39;</span><span class="p">:</span> <span class="n">CHO</span><span class="p">,</span> <span class="s1">&#39;MACHO&#39;</span><span class="p">:</span> <span class="n">MACHO</span>
    <span class="p">})</span></div>


<span class="sd">&quot;&quot;&quot;</span>

<span class="sd">2.	反趋向指标</span>
<span class="sd">主要捕捉趋势的转折点</span>

<span class="sd">随机指标KDJ</span>
<span class="sd">乖离率 BIAS</span>
<span class="sd">变动速率 ROC</span>
<span class="sd">顺势指标 CCI</span>
<span class="sd">威廉指标 W&amp;R</span>
<span class="sd">震荡量(变动速率) OSC</span>
<span class="sd">相对强弱指标 RSI</span>
<span class="sd">动态买卖指标 ADTM</span>

<span class="sd">&quot;&quot;&quot;</span>


<div class="viewcode-block" id="QA_indicator_KDJ"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_KDJ">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_KDJ</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">9</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">H</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span>
    <span class="n">L</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span>

    <span class="n">RSV</span> <span class="o">=</span> <span class="p">(</span><span class="n">C</span> <span class="o">-</span> <span class="n">LLV</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">HHV</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">-</span> <span class="n">LLV</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">K</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">RSV</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span>
    <span class="n">D</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">K</span><span class="p">,</span> <span class="n">M2</span><span class="p">)</span>
    <span class="n">J</span> <span class="o">=</span> <span class="mi">3</span> <span class="o">*</span> <span class="n">K</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">D</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;KDJ_K&#39;</span><span class="p">:</span> <span class="n">K</span><span class="p">,</span> <span class="s1">&#39;KDJ_D&#39;</span><span class="p">:</span> <span class="n">D</span><span class="p">,</span> <span class="s1">&#39;KDJ_J&#39;</span><span class="p">:</span> <span class="n">J</span><span class="p">}</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_BIAS"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_BIAS">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_BIAS</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N1</span><span class="p">,</span> <span class="n">N2</span><span class="p">,</span> <span class="n">N3</span><span class="p">):</span>
    <span class="s1">&#39;乖离率&#39;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">BIAS1</span> <span class="o">=</span> <span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N1</span><span class="p">))</span> <span class="o">/</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">BIAS2</span> <span class="o">=</span> <span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N2</span><span class="p">))</span> <span class="o">/</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N2</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">BIAS3</span> <span class="o">=</span> <span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N3</span><span class="p">))</span> <span class="o">/</span> <span class="n">MA</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="n">N3</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;BIAS1&#39;</span><span class="p">:</span> <span class="n">BIAS1</span><span class="p">,</span> <span class="s1">&#39;BIAS2&#39;</span><span class="p">:</span> <span class="n">BIAS2</span><span class="p">,</span> <span class="s1">&#39;BIAS3&#39;</span><span class="p">:</span> <span class="n">BIAS3</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_ROC"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_ROC">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_ROC</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
    <span class="s1">&#39;变动率指标&#39;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">roc</span> <span class="o">=</span> <span class="mi">100</span> <span class="o">*</span> <span class="p">(</span><span class="n">C</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span> <span class="o">/</span> <span class="n">REF</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">ROCMA</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">roc</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;ROC&#39;</span><span class="p">:</span> <span class="n">roc</span><span class="p">,</span> <span class="s1">&#39;ROCMA&#39;</span><span class="p">:</span> <span class="n">ROCMA</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_CCI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_CCI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_CCI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    TYP:=(HIGH+LOW+CLOSE)/3;</span>
<span class="sd">    CCI:(TYP-MA(TYP,N))/(0.015*AVEDEV(TYP,N));</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">typ</span> <span class="o">=</span> <span class="p">(</span><span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">])</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">cci</span> <span class="o">=</span> <span class="p">((</span><span class="n">typ</span> <span class="o">-</span> <span class="n">MA</span><span class="p">(</span><span class="n">typ</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="mf">0.015</span> <span class="o">*</span> <span class="n">AVEDEV</span><span class="p">(</span><span class="n">typ</span><span class="p">,</span> <span class="n">N</span><span class="p">)))</span>
    <span class="n">a</span> <span class="o">=</span> <span class="mi">100</span>
    <span class="n">b</span> <span class="o">=</span> <span class="o">-</span><span class="mi">100</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;CCI&#39;</span><span class="p">:</span> <span class="n">cci</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="n">a</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="n">b</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_WR"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_WR">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_WR</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="p">,</span> <span class="n">N1</span><span class="p">):</span>
    <span class="s1">&#39;威廉指标&#39;</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">WR1</span> <span class="o">=</span> <span class="mi">100</span> <span class="o">*</span> <span class="p">(</span><span class="n">HHV</span><span class="p">(</span><span class="n">HIGH</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">-</span> <span class="n">CLOSE</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">HHV</span><span class="p">(</span><span class="n">HIGH</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">-</span> <span class="n">LLV</span><span class="p">(</span><span class="n">LOW</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span>
    <span class="n">WR2</span> <span class="o">=</span> <span class="mi">100</span> <span class="o">*</span> <span class="p">(</span><span class="n">HHV</span><span class="p">(</span><span class="n">HIGH</span><span class="p">,</span> <span class="n">N1</span><span class="p">)</span> <span class="o">-</span> <span class="n">CLOSE</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">HHV</span><span class="p">(</span><span class="n">HIGH</span><span class="p">,</span> <span class="n">N1</span><span class="p">)</span> <span class="o">-</span> <span class="n">LLV</span><span class="p">(</span><span class="n">LOW</span><span class="p">,</span> <span class="n">N1</span><span class="p">))</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;WR1&#39;</span><span class="p">:</span> <span class="n">WR1</span><span class="p">,</span> <span class="s1">&#39;WR2&#39;</span><span class="p">:</span> <span class="n">WR2</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_OSC"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_OSC">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_OSC</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;变动速率线</span>

<span class="sd">    震荡量指标OSC，也叫变动速率线。属于超买超卖类指标,是从移动平均线原理派生出来的一种分析指标。</span>

<span class="sd">    它反应当日收盘价与一段时间内平均收盘价的差离值,从而测出股价的震荡幅度。</span>

<span class="sd">    按照移动平均线原理，根据OSC的值可推断价格的趋势，如果远离平均线，就很可能向平均线回归。</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">OS</span> <span class="o">=</span> <span class="p">(</span><span class="n">C</span> <span class="o">-</span> <span class="n">MA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">MAOSC</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">OS</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;OSC&#39;</span><span class="p">:</span> <span class="n">OS</span><span class="p">,</span> <span class="s1">&#39;MAOSC&#39;</span><span class="p">:</span> <span class="n">MAOSC</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_RSI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_RSI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_RSI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N1</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">N2</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">N3</span><span class="o">=</span><span class="mi">9</span><span class="p">):</span>
    <span class="s1">&#39;相对强弱指标RSI1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;&#39;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">LC</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">RSI1</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">N1</span><span class="p">)</span> <span class="o">/</span> <span class="n">SMA</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span><span class="p">),</span> <span class="n">N1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">RSI2</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">N2</span><span class="p">)</span> <span class="o">/</span> <span class="n">SMA</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span><span class="p">),</span> <span class="n">N2</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">RSI3</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">N3</span><span class="p">)</span> <span class="o">/</span> <span class="n">SMA</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span><span class="p">),</span> <span class="n">N3</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;RSI1&#39;</span><span class="p">:</span> <span class="n">RSI1</span><span class="p">,</span> <span class="s1">&#39;RSI2&#39;</span><span class="p">:</span> <span class="n">RSI2</span><span class="p">,</span> <span class="s1">&#39;RSI3&#39;</span><span class="p">:</span> <span class="n">RSI3</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_ADTM"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_ADTM">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_ADTM</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">8</span><span class="p">):</span>
    <span class="s1">&#39;动态买卖气指标&#39;</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span>
    <span class="n">OPEN</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span>
    <span class="n">DTM</span> <span class="o">=</span> <span class="n">IF</span><span class="p">(</span><span class="n">OPEN</span> <span class="o">&lt;=</span> <span class="n">REF</span><span class="p">(</span><span class="n">OPEN</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">MAX</span><span class="p">(</span>
        <span class="p">(</span><span class="n">HIGH</span> <span class="o">-</span> <span class="n">OPEN</span><span class="p">),</span> <span class="p">(</span><span class="n">OPEN</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">OPEN</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
    <span class="n">DBM</span> <span class="o">=</span> <span class="n">IF</span><span class="p">(</span><span class="n">OPEN</span> <span class="o">&gt;=</span> <span class="n">REF</span><span class="p">(</span><span class="n">OPEN</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">MAX</span><span class="p">((</span><span class="n">OPEN</span> <span class="o">-</span> <span class="n">LOW</span><span class="p">),</span> <span class="p">(</span><span class="n">OPEN</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">OPEN</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
    <span class="n">STM</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">DTM</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">SBM</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">DBM</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">ADTM1</span> <span class="o">=</span> <span class="n">IF</span><span class="p">(</span><span class="n">STM</span> <span class="o">&gt;</span> <span class="n">SBM</span><span class="p">,</span> <span class="p">(</span><span class="n">STM</span> <span class="o">-</span> <span class="n">SBM</span><span class="p">)</span> <span class="o">/</span> <span class="n">STM</span><span class="p">,</span>
               <span class="n">IF</span><span class="p">(</span><span class="n">STM</span> <span class="o">==</span> <span class="n">SBM</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">(</span><span class="n">STM</span> <span class="o">-</span> <span class="n">SBM</span><span class="p">)</span> <span class="o">/</span> <span class="n">SBM</span><span class="p">))</span>
    <span class="n">MAADTM</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">ADTM1</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;ADTM&#39;</span><span class="p">:</span> <span class="n">ADTM1</span><span class="p">,</span> <span class="s1">&#39;MAADTM&#39;</span><span class="p">:</span> <span class="n">MAADTM</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">3.	量能指标</span>
<span class="sd">通过成交量的大小和变化研判趋势变化</span>
<span class="sd">容量指标 VR</span>
<span class="sd">量相对强弱 VRSI</span>
<span class="sd">能量指标 CR</span>
<span class="sd">人气意愿指标 ARBR</span>
<span class="sd">成交量标准差 VSTD&quot;&quot;&quot;</span>


<div class="viewcode-block" id="QA_indicator_VR"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_VR">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_VR</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">M3</span><span class="o">=</span><span class="mi">200</span><span class="p">):</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">LC</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">VR</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">&gt;</span> <span class="n">LC</span><span class="p">,</span> <span class="n">VOL</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">M1</span><span class="p">)</span><span class="o">/</span><span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">&lt;=</span> <span class="n">LC</span><span class="p">,</span> <span class="n">VOL</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">M1</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span>
    <span class="n">a</span> <span class="o">=</span> <span class="n">M2</span>
    <span class="n">b</span> <span class="o">=</span> <span class="n">M3</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;VR&#39;</span><span class="p">:</span> <span class="n">VR</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="n">a</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="n">b</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_VRSI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_VRSI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_VRSI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>

    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">vrsi</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="n">VOL</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">VOL</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">),</span> <span class="n">N</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> \
        <span class="n">SMA</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">VOL</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">VOL</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">N</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;VRSI&#39;</span><span class="p">:</span> <span class="n">vrsi</span><span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_CR"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_CR">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_CR</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">M3</span><span class="o">=</span><span class="mi">20</span><span class="p">):</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">MID</span> <span class="o">=</span> <span class="p">(</span><span class="n">HIGH</span><span class="o">+</span><span class="n">LOW</span><span class="o">+</span><span class="n">CLOSE</span><span class="p">)</span><span class="o">/</span><span class="mi">3</span>

    <span class="n">CR</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">HIGH</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">MID</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">N</span><span class="p">)</span><span class="o">/</span><span class="n">SUM</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">REF</span><span class="p">(</span><span class="n">MID</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">-</span><span class="n">LOW</span><span class="p">),</span> <span class="n">N</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span>
    <span class="n">MA1</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">MA</span><span class="p">(</span><span class="n">CR</span><span class="p">,</span> <span class="n">M1</span><span class="p">),</span> <span class="n">M1</span><span class="o">/</span><span class="mf">2.5</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">MA2</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">MA</span><span class="p">(</span><span class="n">CR</span><span class="p">,</span> <span class="n">M2</span><span class="p">),</span> <span class="n">M2</span><span class="o">/</span><span class="mf">2.5</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">MA3</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">MA</span><span class="p">(</span><span class="n">CR</span><span class="p">,</span> <span class="n">M3</span><span class="p">),</span> <span class="n">M3</span><span class="o">/</span><span class="mf">2.5</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;CR&#39;</span><span class="p">:</span> <span class="n">CR</span><span class="p">,</span> <span class="s1">&#39;MA1&#39;</span><span class="p">:</span> <span class="n">MA1</span><span class="p">,</span> <span class="s1">&#39;MA2&#39;</span><span class="p">:</span> <span class="n">MA2</span><span class="p">,</span> <span class="s1">&#39;MA3&#39;</span><span class="p">:</span> <span class="n">MA3</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_ARBR"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_ARBR">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_ARBR</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">70</span><span class="p">,</span> <span class="n">M3</span><span class="o">=</span><span class="mi">150</span><span class="p">):</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">OPEN</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span>
    <span class="n">AR</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">HIGH</span><span class="o">-</span><span class="n">OPEN</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span><span class="o">/</span><span class="n">SUM</span><span class="p">(</span><span class="n">OPEN</span><span class="o">-</span><span class="n">LOW</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span>
    <span class="n">BR</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">HIGH</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">M1</span><span class="p">)</span> <span class="o">/</span> \
        <span class="n">SUM</span><span class="p">(</span><span class="n">MAX</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">-</span><span class="n">LOW</span><span class="p">),</span> <span class="n">M1</span><span class="p">)</span><span class="o">*</span><span class="mi">100</span>
    <span class="n">a</span> <span class="o">=</span> <span class="n">M2</span>
    <span class="n">b</span> <span class="o">=</span> <span class="n">M3</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;AR&#39;</span><span class="p">:</span> <span class="n">AR</span><span class="p">,</span> <span class="s1">&#39;BR&#39;</span><span class="p">:</span> <span class="n">BR</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="n">a</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="n">b</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_VSTD"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_VSTD">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_VSTD</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">10</span><span class="p">):</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">vstd</span> <span class="o">=</span> <span class="n">STD</span><span class="p">(</span><span class="n">VOL</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;VSTD&#39;</span><span class="p">:</span> <span class="n">vstd</span><span class="p">})</span></div>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">4.	量价指标</span>
<span class="sd">通过成交量和股价变动关系分析未来趋势</span>
<span class="sd">震荡升降指标ASI</span>
<span class="sd">价量趋势PVT</span>
<span class="sd">能量潮OBV</span>
<span class="sd">量价趋势VPT</span>
<span class="sd">&quot;&quot;&quot;</span>


<div class="viewcode-block" id="QA_indicator_ASI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_ASI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_ASI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">M2</span><span class="o">=</span><span class="mi">10</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    LC=REF(CLOSE,1);</span>
<span class="sd">    AA=ABS(HIGH-LC);</span>
<span class="sd">    BB=ABS(LOW-LC);</span>
<span class="sd">    CC=ABS(HIGH-REF(LOW,1));</span>
<span class="sd">    DD=ABS(LC-REF(OPEN,1));</span>
<span class="sd">    R=IF(AA&gt;BB AND AA&gt;CC,AA+BB/2+DD/4,IF(BB&gt;CC AND BB&gt;AA,BB+AA/2+DD/4,CC+DD/4));</span>
<span class="sd">    X=(CLOSE-LC+(CLOSE-OPEN)/2+LC-REF(OPEN,1));</span>
<span class="sd">    SI=16*X/R*MAX(AA,BB);</span>
<span class="sd">    ASI:SUM(SI,M1);</span>
<span class="sd">    ASIT:MA(ASI,M2);</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span>
    <span class="n">OPEN</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;open&#39;</span><span class="p">]</span>
    <span class="n">LC</span> <span class="o">=</span> <span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">AA</span> <span class="o">=</span> <span class="n">ABS</span><span class="p">(</span><span class="n">HIGH</span> <span class="o">-</span> <span class="n">LC</span><span class="p">)</span>
    <span class="n">BB</span> <span class="o">=</span> <span class="n">ABS</span><span class="p">(</span><span class="n">LOW</span><span class="o">-</span><span class="n">LC</span><span class="p">)</span>
    <span class="n">CC</span> <span class="o">=</span> <span class="n">ABS</span><span class="p">(</span><span class="n">HIGH</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">LOW</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
    <span class="n">DD</span> <span class="o">=</span> <span class="n">ABS</span><span class="p">(</span><span class="n">LC</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">OPEN</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>

    <span class="n">R</span> <span class="o">=</span> <span class="n">IF</span><span class="p">(</span><span class="n">AA</span> <span class="o">&gt;</span> <span class="n">BB</span> <span class="ow">and</span> <span class="n">AA</span> <span class="o">&gt;</span> <span class="n">CC</span><span class="p">,</span> <span class="n">AA</span><span class="o">+</span><span class="n">BB</span><span class="o">/</span><span class="mi">2</span><span class="o">+</span><span class="n">DD</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span>
           <span class="n">IF</span><span class="p">(</span><span class="n">BB</span> <span class="o">&gt;</span> <span class="n">CC</span> <span class="ow">and</span> <span class="n">BB</span> <span class="o">&gt;</span> <span class="n">AA</span><span class="p">,</span> <span class="n">BB</span><span class="o">+</span><span class="n">AA</span><span class="o">/</span><span class="mi">2</span><span class="o">+</span><span class="n">DD</span><span class="o">/</span><span class="mi">4</span><span class="p">,</span> <span class="n">CC</span><span class="o">+</span><span class="n">DD</span><span class="o">/</span><span class="mi">4</span><span class="p">))</span>
    <span class="n">X</span> <span class="o">=</span> <span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LC</span> <span class="o">+</span> <span class="p">(</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">OPEN</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">LC</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">OPEN</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
    <span class="n">SI</span> <span class="o">=</span> <span class="mi">16</span><span class="o">*</span><span class="n">X</span><span class="o">/</span><span class="n">R</span><span class="o">*</span><span class="n">MAX</span><span class="p">(</span><span class="n">AA</span><span class="p">,</span> <span class="n">BB</span><span class="p">)</span>
    <span class="n">ASI</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">SI</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span>
    <span class="n">ASIT</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">ASI</span><span class="p">,</span> <span class="n">M2</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;ASI&#39;</span><span class="p">:</span> <span class="n">ASI</span><span class="p">,</span> <span class="s1">&#39;ASIT&#39;</span><span class="p">:</span> <span class="n">ASIT</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_PVT"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_PVT">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_PVT</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">PVT</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">((</span><span class="n">CLOSE</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">/</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="n">VOL</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;PVT&#39;</span><span class="p">:</span> <span class="n">PVT</span><span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_OBV"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_OBV">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_OBV</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;能量潮&quot;&quot;&quot;</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;OBV&#39;</span><span class="p">:</span> <span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">&gt;</span> <span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">VOL</span><span class="p">,</span> <span class="n">IF</span><span class="p">(</span><span class="n">CLOSE</span> <span class="o">&lt;</span> <span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="o">-</span><span class="n">VOL</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="mi">0</span><span class="p">)</span><span class="o">/</span><span class="mi">10000</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_VPT"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_VPT">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_VPT</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">51</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">volume</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>
    <span class="n">VPT</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">VOL</span><span class="o">*</span><span class="p">(</span><span class="n">CLOSE</span><span class="o">-</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">/</span><span class="n">REF</span><span class="p">(</span><span class="n">CLOSE</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">MAVPT</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">VPT</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;VPT&#39;</span><span class="p">:</span> <span class="n">VPT</span><span class="p">,</span> <span class="s1">&#39;MAVPT&#39;</span><span class="p">:</span> <span class="n">MAVPT</span>
    <span class="p">})</span></div>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">5.	压力支撑指标</span>
<span class="sd">主要用于分析股价目前收到的压力和支撑</span>
<span class="sd">布林带 BOLL</span>
<span class="sd">麦克指标 MIKE</span>
<span class="sd">&quot;&quot;&quot;</span>


<div class="viewcode-block" id="QA_indicator_BOLL"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_BOLL">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_BOLL</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">P</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
    <span class="s1">&#39;布林线&#39;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">boll</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">UB</span> <span class="o">=</span> <span class="n">boll</span> <span class="o">+</span> <span class="n">P</span> <span class="o">*</span> <span class="n">STD</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">LB</span> <span class="o">=</span> <span class="n">boll</span> <span class="o">-</span> <span class="n">P</span> <span class="o">*</span> <span class="n">STD</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;BOLL&#39;</span><span class="p">:</span> <span class="n">boll</span><span class="p">,</span> <span class="s1">&#39;UB&#39;</span><span class="p">:</span> <span class="n">UB</span><span class="p">,</span> <span class="s1">&#39;LB&#39;</span><span class="p">:</span> <span class="n">LB</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_MIKE"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_MIKE">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_MIKE</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">12</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    MIKE指标</span>
<span class="sd">    指标说明</span>
<span class="sd">    MIKE是另外一种形式的路径指标。</span>
<span class="sd">    买卖原则</span>
<span class="sd">    1  WEAK-S，MEDIUM-S，STRONG-S三条线代表初级、中级、强力支撑。</span>
<span class="sd">    2  WEAK-R，MEDIUM-R，STRONG-R三条线代表初级、中级、强力压力。</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">HIGH</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span>
    <span class="n">LOW</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span>

    <span class="n">TYP</span> <span class="o">=</span> <span class="p">(</span><span class="n">HIGH</span><span class="o">+</span><span class="n">LOW</span><span class="o">+</span><span class="n">CLOSE</span><span class="p">)</span><span class="o">/</span><span class="mi">3</span>
    <span class="n">LL</span> <span class="o">=</span> <span class="n">LLV</span><span class="p">(</span><span class="n">LOW</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">HH</span> <span class="o">=</span> <span class="n">HHV</span><span class="p">(</span><span class="n">HIGH</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>

    <span class="n">WR</span> <span class="o">=</span> <span class="n">TYP</span><span class="o">+</span><span class="p">(</span><span class="n">TYP</span><span class="o">-</span><span class="n">LL</span><span class="p">)</span>
    <span class="n">MR</span> <span class="o">=</span> <span class="n">TYP</span><span class="o">+</span><span class="p">(</span><span class="n">HH</span><span class="o">-</span><span class="n">LL</span><span class="p">)</span>
    <span class="n">SR</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">HH</span><span class="o">-</span><span class="n">LL</span>
    <span class="n">WS</span> <span class="o">=</span> <span class="n">TYP</span><span class="o">-</span><span class="p">(</span><span class="n">HH</span><span class="o">-</span><span class="n">TYP</span><span class="p">)</span>
    <span class="n">MS</span> <span class="o">=</span> <span class="n">TYP</span><span class="o">-</span><span class="p">(</span><span class="n">HH</span><span class="o">-</span><span class="n">LL</span><span class="p">)</span>
    <span class="n">SS</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">LL</span><span class="o">-</span><span class="n">HH</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span>
        <span class="s1">&#39;WR&#39;</span><span class="p">:</span> <span class="n">WR</span><span class="p">,</span> <span class="s1">&#39;MR&#39;</span><span class="p">:</span> <span class="n">MR</span><span class="p">,</span> <span class="s1">&#39;SR&#39;</span><span class="p">:</span> <span class="n">SR</span><span class="p">,</span>
        <span class="s1">&#39;WS&#39;</span><span class="p">:</span> <span class="n">WS</span><span class="p">,</span> <span class="s1">&#39;MS&#39;</span><span class="p">:</span> <span class="n">MS</span><span class="p">,</span> <span class="s1">&#39;SS&#39;</span><span class="p">:</span> <span class="n">SS</span>
    <span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_BBI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_BBI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_BBI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N1</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">N2</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">N3</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">N4</span><span class="o">=</span><span class="mi">24</span><span class="p">):</span>
    <span class="s1">&#39;多空指标&#39;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">bbi</span> <span class="o">=</span> <span class="p">(</span><span class="n">MA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N1</span><span class="p">)</span> <span class="o">+</span> <span class="n">MA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N2</span><span class="p">)</span> <span class="o">+</span> <span class="n">MA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N3</span><span class="p">)</span> <span class="o">+</span> <span class="n">MA</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="n">N4</span><span class="p">))</span> <span class="o">/</span> <span class="mi">4</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;BBI&#39;</span><span class="p">:</span> <span class="n">bbi</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_MFI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_MFI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_MFI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    资金指标</span>
<span class="sd">    TYP := (HIGH + LOW + CLOSE)/3;</span>
<span class="sd">    V1:=SUM(IF(TYP&gt;REF(TYP,1),TYP*VOL,0),N)/SUM(IF(TYP&lt;REF(TYP,1),TYP*VOL,0),N);</span>
<span class="sd">    MFI:100-(100/(1+V1));</span>
<span class="sd">    赋值: (最高价 + 最低价 + 收盘价)/3</span>
<span class="sd">    V1赋值:如果TYP&gt;1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和/如果TYP&lt;1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和</span>
<span class="sd">    输出资金流量指标:100-(100/(1+V1))</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">H</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span>
    <span class="n">L</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span>
    <span class="n">VOL</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;volume&#39;</span><span class="p">]</span>
    <span class="n">TYP</span> <span class="o">=</span> <span class="p">(</span><span class="n">C</span> <span class="o">+</span> <span class="n">H</span> <span class="o">+</span> <span class="n">L</span><span class="p">)</span> <span class="o">/</span> <span class="mi">3</span>
    <span class="n">V1</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">TYP</span> <span class="o">&gt;</span> <span class="n">REF</span><span class="p">(</span><span class="n">TYP</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">TYP</span> <span class="o">*</span> <span class="n">VOL</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">N</span><span class="p">)</span> <span class="o">/</span> \
        <span class="n">SUM</span><span class="p">(</span><span class="n">IF</span><span class="p">(</span><span class="n">TYP</span> <span class="o">&lt;</span> <span class="n">REF</span><span class="p">(</span><span class="n">TYP</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">TYP</span> <span class="o">*</span> <span class="n">VOL</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">mfi</span> <span class="o">=</span> <span class="mi">100</span> <span class="o">-</span> <span class="p">(</span><span class="mi">100</span> <span class="o">/</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">V1</span><span class="p">))</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;MFI&#39;</span><span class="p">:</span> <span class="n">mfi</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_ATR"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_ATR">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_ATR</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    输出TR:(最高价-最低价)和昨收-最高价的绝对值的较大值和昨收-最低价的绝对值的较大值</span>
<span class="sd">    输出真实波幅:TR的N日简单移动平均</span>
<span class="sd">    算法：今日振幅、今日最高与昨收差价、今日最低与昨收差价中的最大值，为真实波幅，求真实波幅的N日移动平均</span>

<span class="sd">    参数：N　天数，一般取14</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">C</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">H</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span>
    <span class="n">L</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span>
    <span class="n">TR</span> <span class="o">=</span> <span class="n">MAX</span><span class="p">(</span><span class="n">MAX</span><span class="p">((</span><span class="n">H</span> <span class="o">-</span> <span class="n">L</span><span class="p">),</span> <span class="n">ABS</span><span class="p">(</span><span class="n">REF</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">-</span> <span class="n">H</span><span class="p">)),</span> <span class="n">ABS</span><span class="p">(</span><span class="n">REF</span><span class="p">(</span><span class="n">C</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">-</span> <span class="n">L</span><span class="p">))</span>
    <span class="n">atr</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">TR</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s1">&#39;TR&#39;</span><span class="p">:</span> <span class="n">TR</span><span class="p">,</span> <span class="s1">&#39;ATR&#39;</span><span class="p">:</span> <span class="n">atr</span><span class="p">})</span></div>


<div class="viewcode-block" id="QA_indicator_SKDJ"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_SKDJ">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_SKDJ</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">9</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    1.指标&gt;80 时，回档机率大；指标&lt;20 时，反弹机率大；</span>
<span class="sd">    2.K在20左右向上交叉D时，视为买进信号参考； </span>
<span class="sd">    3.K在80左右向下交叉D时，视为卖出信号参考；</span>
<span class="sd">    4.SKDJ波动于50左右的任何讯号，其作用不大。</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">CLOSE</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;close&#39;</span><span class="p">]</span>
    <span class="n">LOWV</span> <span class="o">=</span> <span class="n">LLV</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">],</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">HIGHV</span> <span class="o">=</span> <span class="n">HHV</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">],</span> <span class="n">N</span><span class="p">)</span>
    <span class="n">RSV</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">((</span><span class="n">CLOSE</span> <span class="o">-</span> <span class="n">LOWV</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">HIGHV</span> <span class="o">-</span> <span class="n">LOWV</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">K</span> <span class="o">=</span> <span class="n">EMA</span><span class="p">(</span><span class="n">RSV</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">D</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">K</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;RSV&#39;</span><span class="p">:</span> <span class="n">RSV</span><span class="p">,</span> <span class="s1">&#39;SKDJ_K&#39;</span><span class="p">:</span> <span class="n">K</span><span class="p">,</span> <span class="s1">&#39;SKDJ_D&#39;</span><span class="p">:</span> <span class="n">D</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_DDI"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_DDI">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_DDI</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">,</span> <span class="n">N</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="n">N1</span><span class="o">=</span><span class="mi">26</span><span class="p">,</span> <span class="n">M</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">M1</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    &#39;方向标准离差指数&#39;</span>
<span class="sd">    分析DDI柱状线，由红变绿(正变负)，卖出信号参考；由绿变红，买入信号参考。</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">H</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;high&#39;</span><span class="p">]</span>
    <span class="n">L</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">[</span><span class="s1">&#39;low&#39;</span><span class="p">]</span>
    <span class="n">DMZ</span> <span class="o">=</span> <span class="n">IF</span><span class="p">((</span><span class="n">H</span> <span class="o">+</span> <span class="n">L</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="p">(</span><span class="n">REF</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">REF</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="mi">0</span><span class="p">,</span>
             <span class="n">MAX</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">H</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">ABS</span><span class="p">(</span><span class="n">L</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
    <span class="n">DMF</span> <span class="o">=</span> <span class="n">IF</span><span class="p">((</span><span class="n">H</span> <span class="o">+</span> <span class="n">L</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="p">(</span><span class="n">REF</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">REF</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="mi">0</span><span class="p">,</span>
             <span class="n">MAX</span><span class="p">(</span><span class="n">ABS</span><span class="p">(</span><span class="n">H</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">ABS</span><span class="p">(</span><span class="n">L</span> <span class="o">-</span> <span class="n">REF</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
    <span class="n">DIZ</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">DMZ</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">SUM</span><span class="p">(</span><span class="n">DMZ</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">+</span> <span class="n">SUM</span><span class="p">(</span><span class="n">DMF</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span>
    <span class="n">DIF</span> <span class="o">=</span> <span class="n">SUM</span><span class="p">(</span><span class="n">DMF</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">SUM</span><span class="p">(</span><span class="n">DMF</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span> <span class="o">+</span> <span class="n">SUM</span><span class="p">(</span><span class="n">DMZ</span><span class="p">,</span> <span class="n">N</span><span class="p">))</span>
    <span class="n">ddi</span> <span class="o">=</span> <span class="n">DIZ</span> <span class="o">-</span> <span class="n">DIF</span>
    <span class="n">ADDI</span> <span class="o">=</span> <span class="n">SMA</span><span class="p">(</span><span class="n">ddi</span><span class="p">,</span> <span class="n">N1</span><span class="p">,</span> <span class="n">M</span><span class="p">)</span>
    <span class="n">AD</span> <span class="o">=</span> <span class="n">MA</span><span class="p">(</span><span class="n">ADDI</span><span class="p">,</span> <span class="n">M1</span><span class="p">)</span>
    <span class="n">DICT</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;DDI&#39;</span><span class="p">:</span> <span class="n">ddi</span><span class="p">,</span> <span class="s1">&#39;ADDI&#39;</span><span class="p">:</span> <span class="n">ADDI</span><span class="p">,</span> <span class="s1">&#39;AD&#39;</span><span class="p">:</span> <span class="n">AD</span><span class="p">}</span>

    <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">DICT</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_indicator_shadow"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.QA_indicator_shadow">[docs]</a><span class="k">def</span> <span class="nf">QA_indicator_shadow</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    上下影线指标</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">{</span>
        <span class="s1">&#39;LOW&#39;</span><span class="p">:</span> <span class="n">lower_shadow</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">),</span> <span class="s1">&#39;UP&#39;</span><span class="p">:</span> <span class="n">upper_shadow</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">),</span>
        <span class="s1">&#39;BODY&#39;</span><span class="p">:</span> <span class="n">body</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">),</span> <span class="s1">&#39;BODY_ABS&#39;</span><span class="p">:</span> <span class="n">body_abs</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">),</span> <span class="s1">&#39;PRICE_PCG&#39;</span><span class="p">:</span> <span class="n">price_pcg</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">)</span>
    <span class="p">}</span></div>


<div class="viewcode-block" id="lower_shadow"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.lower_shadow">[docs]</a><span class="k">def</span> <span class="nf">lower_shadow</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>  <span class="c1"># 下影线</span>
    <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span> <span class="o">-</span> <span class="n">MIN</span><span class="p">(</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span><span class="p">,</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span><span class="p">))</span></div>


<div class="viewcode-block" id="upper_shadow"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.upper_shadow">[docs]</a><span class="k">def</span> <span class="nf">upper_shadow</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>  <span class="c1"># 上影线</span>
    <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span> <span class="o">-</span> <span class="n">MAX</span><span class="p">(</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span><span class="p">,</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span><span class="p">))</span></div>


<div class="viewcode-block" id="body_abs"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.body_abs">[docs]</a><span class="k">def</span> <span class="nf">body_abs</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span> <span class="o">-</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span><span class="p">)</span></div>


<div class="viewcode-block" id="body"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.body">[docs]</a><span class="k">def</span> <span class="nf">body</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">close</span> <span class="o">-</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span></div>


<div class="viewcode-block" id="price_pcg"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.price_pcg">[docs]</a><span class="k">def</span> <span class="nf">price_pcg</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">body</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">)</span> <span class="o">/</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">open</span></div>


<div class="viewcode-block" id="amplitude"><a class="viewcode-back" href="../../../source/QUANTAXIS.QAIndicator.html#QUANTAXIS.QAIndicator.indicators.amplitude">[docs]</a><span class="k">def</span> <span class="nf">amplitude</span><span class="p">(</span><span class="n">DataFrame</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">DataFrame</span><span class="o">.</span><span class="n">high</span> <span class="o">-</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span><span class="p">)</span> <span class="o">/</span> <span class="n">DataFrame</span><span class="o">.</span><span class="n">low</span></div>


<span class="sd">&quot;&quot;&quot;</span>

<span class="sd">6.	大盘指标</span>
<span class="sd">通过涨跌家数研究大盘指数的走势</span>
<span class="sd">涨跌比率 ADR</span>
<span class="sd">绝对幅度指标 ABI</span>
<span class="sd">新三价率 TBR</span>
<span class="sd">腾落指数 ADL</span>
<span class="sd">广量冲力指标</span>
<span class="sd">指数平滑广量 STIX</span>
<span class="sd">&quot;&quot;&quot;</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, yutiansut.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'1.0.39',
            LANGUAGE:'python',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>